﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerGames.FarseerPhysics;
using Microsoft.Xna.Framework;
using FarseerGames.FarseerPhysics.Collisions;
using UnitLibrary.Managers;
using Microsoft.Xna.Framework.Graphics;
using UnitLibrary.GameObjects.Physics;

namespace UnitLibrary.GameObjects
{
    /// <summary>
    /// 
    /// </summary>
    public class CapturePoint : PhyObj
    {        /// <summary>
        /// 
        /// </summary>
        public CapturePoint()
            : base()
        {
            
        }

        /// <summary>
        /// Delegate for when this point is captured
        /// </summary>
        /// <param name="capturePoint"></param>
        public delegate void PointCaptured(CapturePoint capturePoint);

        /// <summary>
        /// public delegate which other classes can use to listen
        /// fired when the point is captured
        /// </summary>
        public PointCaptured OnPointCaptured;
       
        /// <summary>
        /// The amount of time the player has spent on this point
        /// </summary>
        private double _timeOnPoint = 0;

        /// <summary>
        /// The amount of time the player must spend on this point in order to capture it
        /// </summary>
        private double _timeNeededForCapture;

        /// <summary>
        /// 
        /// </summary>
        private bool _isCaptured = false;

        /// <summary>
        /// 
        /// </summary>
        private Geom _playerGeom;

        

        /// <summary>
        /// Returns the amount of time the player has spent on the point
        /// </summary>
        public double TimeOnPoint
        {
            get { return _timeOnPoint; }
        }

        /// <summary>
        /// Returns the amount of time required of the player to spend on this point
        /// </summary>
        public double TimeNeededForCapture
        {
            set { _timeNeededForCapture = value; }
            get { return _timeNeededForCapture; }
        }

        /// <summary>
        /// Returns whether or not this point is captured
        /// </summary>
        public bool IsCaptured
        {
            get { return _isCaptured; }
        }

        /// <summary>
        /// Sets the player position
        /// </summary>
        public void SetPlayerGeom(Geom playerGeom)
        {
            _playerGeom = playerGeom;
        }       
           
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gametime"></param>
        public override void Update(Microsoft.Xna.Framework.GameTime gametime)
        {
            //if (!_isCaptured)
            //{
            //if (_geom.Collide(_playerGeom))
            //    _timeOnPoint += gametime.ElapsedGameTime.TotalMilliseconds;
            
            
            //    if (_timeOnPoint > _timeNeededForCapture)
            //    {
                    
            //            PointIsCaptured();
            //            //Let all listeners of this class's event know that this point has been captured
            //            if (OnPointCaptured != null)
            //                OnPointCaptured(this);
            //            _isCaptured = true;
                    
            //    }
            //}

            base.Update(gametime);
        }        

        /// <summary>
        /// 
        /// </summary>
        /// <param name="spriteBatch"></param>
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
        }
        

        public void PointIsCaptured()
        {
            //_textureColor = Color.Green;
        }
    }
}
